/**
 * Created by yqj on 2017/2/15.
 */
import { knowledgePointManagementResource } from '../../api'

export const labelManagementStore = {
  state: {
    knowledgePoints: {
      '1': {  // 一级知识点
        items: []
      },
      '2': {  // 二级知识点
        items: []
      },
      '3': {  // 三级知识点
        items: []
      }
    }
  },
  actions: {
    FETCH_KNOWLEDGE_POINTS ({ commit, dispatch, state }, { subject, grade, parentId, level }) {
      knowledgePointManagementResource.getKnowledgePoints({subject: subject || null, grade: grade || null, parentId: parentId || null})
        .then(response => {
          let list = response.body.result
          commit('SET_KNOWLEDGE_POINTS', { list, level })
        })
    }
  },
  mutations: {
    SET_KNOWLEDGE_POINTS (state, { list, level }) {
      state.knowledgePoints[level + ''].items = list
    }
  },
  getters: {

  }
}
